AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')

function ENT:Initialize()
	self.Entity:SetNetworkedBool("heldprop",false)
	// Choose model
	model = "models/items/boxsrounds.mdl"
	self.Entity["amount"] = 16
	if (self.Entity["ammotype"] == "pistol") then
		model = "models/items/boxsrounds.mdl"
		self.Entity["amount"] = 16
	elseif (self.Entity["ammotype"] == "357") then
		model = "models/items/357ammobox.mdl"
		self.Entity["amount"] = 6
	elseif (self.Entity["ammotype"] == "smg1") then
		model = "models/items/boxmrounds.mdl"
		self.Entity["amount"] = 32
	elseif (self.Entity["ammotype"] == "ar2") then
		model = "models/items/boxmrounds.mdl"
		self.Entity["amount"] = 30
	elseif (self.Entity["ammotype"] == "Buckshot") then
		model = "models/items/boxbuckshot.mdl"
		self.Entity["amount"] = 36
	elseif (self.Entity["ammotype"] == "SniperRound") then
		model = "models/items/boxflares.mdl"
		self.Entity["amount"] = 5
	end
	
	// Initalize physics
	self.Entity:SetModel(model)
	self.Entity:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
	self.Entity:SetSolid(SOLID_VPHYSICS)
	local phys=self.Entity:GetPhysicsObject()
	phys:SetMass(22)
	if (phys:IsValid()) then phys:Wake() end
end
function ENT:KeyValue(key, value)
	if (self.Entity:IsOutput(key)) then self.Entity:StoreOutput(key,value)
	else self.Entity[key]=value end
end
function ENT:AcceptInput(i, activator, caller)
	me=self.Entity
	if		(i=="Kill") then
		me:Remove()
	end
end
function ENT:Use(activator, caller)
	if (activator:IsPlayer() and caller:IsWorld()) then
		self.Entity:Remove()
		self:TriggerOutput("OnUsed",activator)
		activator:GiveAmmo(self.Entity["amount"],self.Entity["ammotype"])
	end
end
function ENT:IsOutput(o)
	local OUTPUTLIST = { "OnUsed" }
	local r=false
	for i in pairs(OUTPUTLIST) do
		if (o==OUTPUTLIST[i]) then return true end
	end
	return false
end